home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / typecodes.h < prev    next >
C/C++ Source or Header  |  1998-09-15  |  5KB  |  145 lines

  1. /*
  2.  * @(#)typecodes.h    1.10 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /*
  16.  * Type codes  6/12/91
  17.  
  18.     This typecode system allows us to represent the type
  19.     of scalars in a uniform way. For instance, all integer types
  20.     have some bits in common, and are distinguished by a built-in
  21.     size field. Types without multiple sizes don't have a size field.
  22.  
  23.     Scalars may only have sizes which are powers of 2. The size
  24.     field holds the log-based-2 of the object's size.
  25.  
  26.     All run-time types can be encoded in 4 bits. There are more
  27.     compile- time types. These fit in 5 bits.
  28.     Schematically, we have:
  29.         +----+----+----+----+----+
  30.         | c  |    t    |    s    |
  31.         +----+----+----+----+----+
  32.  
  33.         Encoding is:
  34.            c   t  s    type
  35.         -------------------------
  36.            0  00 00    unassigned
  37.            0  00 01    array
  38.            0  00 10    class
  39.            0  00 11    proxy    (OBSOLETE)
  40.            0  01 00    boolean (1 byte)
  41.            0  01 01    char    (2 bytes)
  42.            0  01 1s    float (single=1; double=2)
  43.            0  1u xx    integer (byte=0; short=1; int=2; long=3;
  44.                      u=1 => unsigned)
  45.  
  46.             For runtime types, the size of an object
  47.             is 1<<(t&3)
  48.  
  49.            1  00 00    typedef    (compiler only)
  50.            1  00 01    void    (compiler only)
  51.            1  00 10    func    (compiler only)
  52.            1  00 11    unknown (compiler only)
  53.            1  01 00     error   (compiler only)
  54.  
  55.     Char and Boolean are not int's because they need a different signature,
  56.     so have to be distinguishable, even at runtime. We allow arrays
  57.     of objects, arrays(?), booleans, char, integers, and floats.
  58.     Note that the low-order two bits of all these gives the log of
  59.     the size, except for arrays, of course.
  60.  
  61.     I would prefer not to have unsigned int in the language, but
  62.     don't want to make that decision at this level. We could come up
  63.     with a better encoding of boolean and char if there were no
  64.     unsigned.
  65.  
  66.     The compile-only type values that could be confused with the 
  67.     integer and float scalar types must not ever be used. Value 0 must
  68.     not be assigned a runtime type, as this is used for some sleazy
  69.     trickery in punning types and pointer. In fact, we even have a name
  70.     for it.
  71. */
  72.  
  73. /* If you change these typecodes, you'll have to fix the arrayinfo table
  74.    in gc.c and the {in,}direct_{load,store}_ops tables in
  75.    compiler/tree2code.c */
  76.  
  77. #ifndef _TYPECODES_H_
  78. #define _TYPECODES_H_
  79.  
  80. #define T_NORMAL_OBJECT    0
  81. #define T_XXUNUSEDXX1   1    /* Used to be T_ARRAY */
  82. #define T_CLASS        2
  83. #define T_BOOLEAN    4
  84. #define T_CHAR        5
  85.  
  86. #define T_FLOATING    4    /* add log2 size to get correct code:
  87.                     float has code 6,
  88.                     double has code 7 */
  89. #define T_INTEGER    010
  90. #define T_UINTEGER    014
  91.  
  92. #define    T_MAXNUMERIC    020
  93.  
  94. #define    T_XXUNUSEDXX2    020
  95. #define    T_VOID        021
  96. #define    T_FUNC        022
  97. #define    T_UNKNOWN    023
  98. #define    T_ERROR        024
  99.  
  100. /* for type construction */
  101. #define T_TMASK    034
  102. #define T_LMASK 003
  103. #define T_LSIZE 2
  104. #define T_MKTYPE( t, l )  ( ( (t)&T_TMASK ) | ( (l)&T_LMASK) )
  105.  
  106. /* for type deconstruction */
  107.     /*
  108.      * Because we promise always to let ints and compile-only types be 
  109.      * distinguished by the "t" and "s" bits above, we can simplify
  110.      * some of our predicates by masking out the "c" bit when testing
  111.      * for integers. Thus the T_TS_MASK...
  112.      */
  113. #define T_TS_MASK 034
  114. #define T_ISINTEGER(t)  ( ((t)&030) == T_INTEGER  )
  115. #define T_ISFLOATING(t) ( ((t)&036) == T_FLOAT )
  116. #define T_ISNUMERIC(t)  ( (t) >= T_CHAR && (t) < T_MAXNUMERIC )
  117. #define T_SIZEFIELD(t)    ((t)&T_LMASK)
  118. #define T_ELEMENT_SIZE(t) (1<<T_SIZEFIELD(t))    /* only for some!! */
  119.  
  120. #define T_IS_BIG_TYPE(t) ((t == T_DOUBLE) || (t == T_LONG))
  121. #define T_TYPE_WORDS(t) (T_IS_BIG_TYPE(t) ? 2 : 1)
  122.  
  123. /* nick-names for the usual scalar types */
  124. #define T_FLOAT  T_MKTYPE(T_FLOATING,2)
  125. #define T_DOUBLE T_MKTYPE(T_FLOATING,3)
  126. #define T_BYTE     T_MKTYPE(T_INTEGER,0)
  127. #define T_SHORT     T_MKTYPE(T_INTEGER,1)
  128. #define T_INT     T_MKTYPE(T_INTEGER,2)
  129. #define T_LONG     T_MKTYPE(T_INTEGER,3)
  130.  
  131. #ifdef NO_LONGER_USED
  132. /* We no longer support these types */
  133. #define T_UBYTE     T_MKTYPE(T_UINTEGER,0)
  134. #define T_USHORT T_MKTYPE(T_UINTEGER,1)
  135. #define T_UINT     T_MKTYPE(T_UINTEGER,2)
  136. #define T_ULONG     T_MKTYPE(T_UINTEGER,3)
  137.  
  138. #endif
  139.  
  140. /* only a slight exaggeration */
  141. #define N_TYPECODES    (1<<6)
  142. #define    N_TYPEMASK    (N_TYPECODES-1)
  143.  
  144. #endif /* !_TYPECODES_H_ */
  145.